<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="uft-8">
    <title>JavaScript 语法</title>
    <script>
        // javaScript goes here...
    </script>
    <script src="demo.file.js"></script>
</head>
<body>
<!--mark-up goes here...-->
<!--这是 HTML 中的注释-->
<script>
    function statement() {
        // first statement;
        // second statement;

        // first statement; second statement;

        // first statement;
        // second statement;
    }

    function comment() {
        // 自我提醒: 有注释是好事

        // 自我提醒:
        // 有注释是好事

        /*
         * 自我提醒：
         * 有注释是好事
         * */
    }

    function variable() {
        function sample() {
            var mood = 'happy';
            var age = '33';

            alert(mood);
            alert(age);
        }

        function sample1() {
            var mood;
            var age;
        }

        function sample2() {
            var mood, age;
        }

        function sample3() {
            var mood = 'happy', age = 33;
        }

        function sample4() {
            var mood, age;
            mood = 'happy';
            age = 33;
        }

        function sample5() {
            var mood = 'happy';
            // MOOD = 'sad'; 全局变量
        }

        function sample6() {
            // var my mood ='hayyp'; error
        }

        function sample7() {
            var my_mood = 'happy';
            var myMood = 'happy';
        }
    }

    function dataType() {
        function sample() {
            var age = 'thirty three';
            age = 33;
        }

        function sample1() {
            var mood = 'happy';

            function or() {
                var mood = "happy";
            }
        }

        function sample2() {
            var mood = "don't ask";

            function or() {
                var mood = 'don\'t ask';
            }
        }

        function sample3() {
            var height = "about 5'10\" tall";

            function or() {
                var height = "about 5'10\" tall";
                alert(height);
            }
        }

        function sample4() {
            var age = 33.25;
            var temperature = -20;

            function also() {
                var temperature = -20.33333333;
            }
        }

        function sample5() {
            var sleeping = true;
            var married = true;

            function change() {
                var married = "true";
            }
        }

        function sample6() {
            var beatles = Array(4);

            function or() {
                var beatles = Array();
                beatles[0] = "John";
            }

            function or1() {
                var beatles = Array(4);
                beatles[0] = "John";
                beatles[1] = "Paul";
                beatles[2] = "George";
                beatles[3] = "Ringo";
            }

            function or2() {
                var beatles = Array("John", "Paul", "George", "Ringo");
            }

            function or3() {
                var beatles = ["John", "Paul", "George", "Ringo"];
            }

            function or4() {
                var beatles = [];
                var years = [1940, 1941, 1942, 1943];
                var lennon = ["John", 1940, false];
                var name = "John";
                beatles[0] = name;
            }

            function or5() {
                var beatles = [];
                var names = ["Ringo", "John", "George", "Paul"];
                beatles[1] = names[3];
            }

            function or6() {
                var lennon = ["John", 1940, false];
                var beatles = [];
                beatles[0] = lennon;
            }

            function or7() {
                var lennon = Array();
                lennon["name"] = "John";
                lennon["year"] = 1940;
                lennon["living"] = false;
            }
        }

        function sample7() {
            var lennon = Object();
            lennon.name = 'John';
            lennon.year = 1940;
            lennon.living = false;

            function or() {
                var lennon = {name: "John", year: 1940, living: false};
                var beatles = Array();
                beatles[0] = lennon;
            }

            function or1() {
                var lennon = {};
                var beatles = {};
                beatles.vocalist = lennon;
            }
        }
    }

    function operator() {
        function sample() {
            1 + 4;
            1 + 4 * 5;
            (1 + 4) * 5;
            var total = (1 + 4) * 5;

            var temp_fahrenheit = 95;
            var temp_celsius = (temp_fahrenheit - 32) / 1.8;

            year = year + 1;
            year++;

            var message = "I am feeling " + "happy";
        }

        function sample1() {
            var mood = "happy";
            var message = "I am feeling " + mood;
        }

        function sample2() {
            var year = 2005;
            var message = "The year is " + year;
        }

        function sample3() {
            alert("10" + 20);
            alert(10 + 20);
        }

        function sample4() {
            var year = 2010;
            var message = "The year is ";
            message += year;
            alert(message);
        }
    }

    function conditionalStatement() {
        function sample() {
            // if (condition) {
            //     statements;
            // }
        }

        function sample1() {
            if (1 > 2) {
                alert('The world has gone mad!');
            }
        }

        function sample2() {
            if (1 > 2) {
                alert('The world has gone mad!');
            } else {
                alert('All is well with the world');
            }
        }

        function sample3() {
            var my_mood = 'happy';
            var your_mood = 'sad';
            if (my_mood = your_mood) {
                alert('We both fell the same.');
            }
        }

        function sample4() {
            var my_mood = 'happy';
            var your_mood = 'sad';
            if (my_mood == your_mood) {
                alert('We both fell the same.');
            }

            if (my_mood != your_mood) {
                alert('We\'re feeling different moods.');
            }
        }

        function sample5() {
            var a = false;
            var b = '';
            if (a == b) {
                alert('a equals b');
            }
        }

        function sample6() {
            var a = false;
            var b = '';
            if (a === b) {
                alert('a equals b');
            }
        }

        function sample7() {
            var num = 3;

            if (num >= 5 && num <= 10) {
                alert('The number is in the right range.');
            }

            if (num > 10 || num < 5) {
                alert('The number is not in the right range.');
            }

            if (!(1 > 2)) {
                alert('All is well with the world');
            }

            if (!(num > 10 || num < 5)) {
                alert('The number is in the right range.');
            }
        }

        function sample8() {
            // while (condition) {
            //     statements;
            // }
        }

        function sample9() {
            var count = 1;
            while (count < 11) {
                alert(count);
                count++;
            }
        }

        function sample10() {
            // do {
            //     statements;
            // } while (condition);
        }

        function sample11() {
            var count = 1;
            do {
                alert(count);
            } while (count < 1);
        }

        function sample12() {
            var count = 1;
            do {
                alert(count);
                count++;
            } while (count < 1);
        }

        function sample13() {
            // initialize;
            // while (condition) {
            //     statements;
            //     increment;
            // }

            // for (initial coundition; test coundition; alter coundition){
            //     statements;
            // }
        }

        function sample14() {
            for (var count = 0; count < 11; count++) {
                alert(count);
            }
        }

        function sample15() {
            var beatles = Array("John", "Paul", "Georage", "Ringo");
            for (var i = 0; i < beatles.length; i++) {
                alert(beatles[i]);
            }
        }
    }

    function functions() {
        function sample() {
            function shout() {
                var beatles = Array("John", "Paul", "Georage", "Ringo");
                for (var i = 0; i < beatles.length; i++) {
                    alert(beatles[i]);
                }
            }

            shout();
        }

        function sample1() {
            function name(arguments) {
                // statements
            }
        }

        function sample2() {
            function multiply(num1, num2) {
                var total = num1 * num2;
                alert(total);
            }

            multiply(10, 2);
        }

        function sample3() {
            function multiply(num1, num2) {
                return num1 * num2;
            }

            function convertToCelsius(temp) {
                var result = temp - 32;
                result = result / 1.8;
                return result;
            }

            function call() {
                var tempFahrenheit = 95;
                var tempCelsius = convertToCelsius(tempFahrenheit);
                alert(tempCelsius);
            }
        }

        function sample4() {
            var total = 50;
            var number = square(20);
            alert(total);

            function square(num) {
                total = num * num;
                return total;
            }
        }

        function sample5() {
            function square(num) {
                return num * num;
            }
        }
    }

    function objects() {
        function sample() {
            // object.property
            // object.method()
            // Person.mood
            // Person.age
            // Person.walk();
            // Person.sleep();
            // var jeremy = new Person
            // jeremy.age
            // jeremy.mood
        }

        function sample1() {
            var beatles = new Array();
            var lenght = beatles.length;
            var num = 7.561;
            num = Math.round(num);
            alert(num);
            var currentDate=new Date();
            var totay=currentDate.getDay();
        }
    }
</script>
<script src="demo.file.js"></script>
</body>
</html>